var L_CANCEL_TEXT = "取消";
var L_INSERT_TEXT = "插入";
var L_LINKIMGBORDER_TEXT = "显示图片连接边界";
var L_LINKSELECT_TEXT = "选择公共页面: ";
var L_LINKSELECTPAGE_TEXT = "选择页面";
var L_LINKWEB_TEXT = "在下面添入网站页面URL: ";
var L_PUTITLEFONTFACE_TEXT = "设置字体风格";
var L_PUTITLELINK_TEXT = "插入/编辑连接";
var L_PUTITLETEXTCOLOR_TEXT = "设置正文颜色";
var L_PUTITLEEMOTICON_TEXT = "插入情绪符号";
var L_TIPB_TEXT = "粗体";
var L_TIPCJ_TEXT = "位于中央";
var L_TIPCOPY_TEXT = "复制文本";
var L_TIPCUT_TEXT = "剪切文本";
var L_TIPDINDENT_TEXT = "减少缩进";
var L_TIPFGCOLOR_TEXT = "文本颜色";
var L_TIPFSTYLE_TEXT = "字体类型";
var L_TIPI_TEXT = "斜体";
var L_TIPIINDENT_TEXT = "增加缩进";
var L_TIPLINK_TEXT = "插入链接";
var L_TIPLJ_TEXT = "位于左边";
var L_TIPOL_TEXT = "排序列表";
var L_TIPPASTE_TEXT = "粘贴文本";
var L_TIPRJ_TEXT = "位于右边";
var L_TIPU_TEXT = "下划线";
var L_TIPUL_TEXT = "无序列表";
var L_TIPEMOTICON_TEXT = "插入表情";
var L_EMOTICONPATH_TEXT = "view/face/";
var arEmoticons = new Array("em_01.gif","em_02.gif","em_03.gif","em_04.gif","em_05.gif","em_06.gif","em_07.gif","em_08.gif","em_09.gif","em_10.gif","em_11.gif","em_12.gif","em_13.gif","em_14.gif","em_15.gif","em_16.gif","em_17.gif","em_18.gif","em_19.gif","em_20.gif","em_21.gif","em_22.gif","em_23.gif","em_24.gif","em_25.gif","em_26.gif","em_27.gif","em_28.gif","em_29.gif","em_30.gif","em_31.gif","em_32.gif","em_33.gif","em_34.gif","em_35.gif","em_36.gif","em_37.gif","em_38.gif","em_39.gif","em_40.gif","em_41.gif","em_42.gif","em_43.gif","em_44.gif","em_45.gif");
var L_FONTARIAL_TEXT = "Arial";
var L_FONTARIALDEF_TEXT = "Geneva, Arial, Sans-serif";
var L_FONTARIALBLACK_TEXT = "Arial Black";
var L_FONTARIALBLACKDEF_TEXT = "Arial Black, Geneva, Arial, Sans-serif";
var L_FONTCOURIERNEW_TEXT = "Courier New";
var L_FONTCOURIERNEWDEF_TEXT = "Courier New, Courier, Monospace";
var L_FONTLISHU_TEXT = "隶书";
var L_FONTLISHUDEF_TEXT = "隶书 , 宋体";
var L_FONTVERDANA_TEXT = "Verdana";
var L_FONTVERDANADEF_TEXT = "Verdana, Geneva, Arial, Sans-serif";
var L_LUCIDAHAND_TEXT = "Lucida Handwriting";
var L_LUCIDAHANDDEF_TEXT = "Lucida Handwriting, Cursive";
var L_KAITI_TEXT = "楷体";
var L_KAITIDEF_TEXT = "楷体_GB2312 , 楷体 , 宋体";
var L_WEBDINGS_TEXT = "Webdings";
var L_WEBDINGSDEF_TEXT = "Webdings";
var L_WINGDINGS_TEXT = "Wingdings";
var L_WINGDINGSDEF_TEXT = "Wingdings";
var L_YOUYUAN_TEXT = "幼圆";
var L_YOUYUANDEF_TEXT = "幼圆 , 宋体";

function _CFont(szDef,szText,bSymbol) {
return new Array(szDef,szText,bSymbol);
};
defaultFonts = new Array();
defaultFonts[0] = _CFont(L_FONTARIALBLACKDEF_TEXT, L_FONTARIALBLACK_TEXT, false);
defaultFonts[1] = _CFont(L_FONTARIALDEF_TEXT, L_FONTARIAL_TEXT, false);
defaultFonts[2] = _CFont(L_FONTCOURIERNEWDEF_TEXT, L_FONTCOURIERNEW_TEXT, false);
defaultFonts[3] = _CFont(L_FONTVERDANADEF_TEXT, L_FONTVERDANA_TEXT, false);
defaultFonts[4] = _CFont(L_LUCIDAHANDDEF_TEXT,L_LUCIDAHAND_TEXT, false);
defaultFonts[5] = _CFont(L_KAITIDEF_TEXT,L_KAITI_TEXT, false);
defaultFonts[6] = _CFont(L_WEBDINGSDEF_TEXT, L_WEBDINGS_TEXT, true);
defaultFonts[7] = _CFont(L_FONTLISHUDEF_TEXT, L_FONTLISHU_TEXT, false);
defaultFonts[8] = _CFont(L_WINGDINGSDEF_TEXT, L_WINGDINGS_TEXT, true);
defaultFonts[9] = _CFont(L_YOUYUANDEF_TEXT, L_YOUYUAN_TEXT, false);


var L_TOOLBARGIF_TEXT = "{*$aOut.imgurl*}htmled_icons.gif";



// EDITOR PUBLIC (API)

function setHTML(szHTML)
{
if (g_state.bMode)
idEditbox.document.body.innerHTML = szHTML
else
idEditbox.document.body.innerText = szHTML
_Editor_MoveSelection(true)
}

function getHTML()
{
        var szRet = (g_state.bMode ? idEditbox.document.body.innerHTML : idEditbox.document.body.innerText)
        return szRet
}

function insertHTML(szHTML)
{
var sType
var sel = g_state.GetSelection()
sType = sel.type
if (g_state.bMode) {
if (sType=="Control")
sel.item(0).outerHTML = szHTML
else
sel.pasteHTML(szHTML)
}
else
sel.text = szHTML
}

function setFocus() {
	if(! idPopup.document._show) idEditbox.focus()
}

function setBGColor(szValue)
{
g_state.bgColor = szValue
if (g_state.bMode)
idEditbox.document.body.bgColor = g_state.bgColor
}

// EDITOR PRIVATE
function _Format(szHow, szValue) {
var oSel        = g_state.GetSelection()
var sType = oSel.type
var oTarget = (sType == "None" ? idEditbox.document : oSel)
var oBlock = (oSel.parentElement != null ? _CUtil_GetBlock(oSel.parentElement()) : oSel.item(0))
//setFocus()
switch(szHow)
{
case "Justify":
if (oBlock)
{
oBlock.style.textAlign = ""
if (((oBlock.tagName=="TABLE") || (oBlock.tagName=="IMG")) && (("left"==oBlock.align) && ("Left"==szValue))) {
oBlock.align = ""
break;
}
oBlock.align = szValue
if ((oBlock.tagName=="HR") || ((oBlock.tagName=="IMG") && szValue!="Center")) break;
}
szHow=szHow+szValue
szValue=""
// Fall through
default:
oTarget.execCommand(szHow, false, szValue)
break
}
g_state.RestoreSelection()
//commented out by Bob.
//setFocus()
return true
}

var g_state
function _initEditor() {
g_state = new _CState()
window.onresize = _setSize
var sz = ""
sz += ""
+ "<STYLE>"
//+        ".DataBound{border:1 solid #999999;margin:1;font-family:Courier;background:#F1F1F1}\n"
//+        ".textMode {border-top: 1px black solid;font: 10pt courier}"
+		 " TD {border:1px gray solid}"
+        "BODY {border: 1px #C6C6C6 solid;border-top:none;font-size:14px}"
+		 "P,OL,UL {margin-top:3px;margin-bottom:3px}"
+		 "HR {width:80%}"
//+		 "img {border-width:0px}"
//+		 "a img {border-width:1px}"
+ "</STYLE>"
+ "<BODY ONCONTEXTMENU=\"return false\" scroll=yes>"
//+ INIT_HTML
//+"<DIV></DIV>"
+ "</BODY>"
_CPopup_Init()
idEditbox.document.designMode = "on"
idEditbox.document.open("text/html","replace")
idEditbox.document.write(sz)
idEditbox.document.close()
idEditbox.document.body.onblur = g_state.SaveSelection
idEditbox.document.onkeydown = _Editor_KeyDownHandler
idEditbox.document.onmousedown = _Editor_ClickHandler
idEditbox.document.ondblclick = _Editor_DblClickHandler
idEditbox.document.onclick = _CPopup_Hide
setTimeout("_pageReady()",0)
}

function _Editor_MoveSelection(bDir) {
var tr = idEditbox.document.body.createTextRange()
tr.collapse(bDir)
tr.select()
}

function _Editor_ClickHandler() {
g_state.selection = null
}

function _Editor_KeyDownHandler() {
var ev = this.parentWindow.event
if (ev.keyCode==9)
g_state.SaveSelection()
else
g_state.selection=null
}

function _Editor_DblClickHandler() {
// Shortcuts
var el = this.parentWindow.event.srcElement
if (el.tagName=="IMG") {
el.removeAttribute("width")
el.removeAttribute("height")
el.style.removeAttribute("width")
el.style.removeAttribute("height")
el.width = el.width
el.height = el.height
}
}

function _setSize() {
document.all.idEditbox.style.pixelHeight = document.body.clientHeight - idToolbar.offsetHeight
document.all.idPopup.style.pixelLeft = (document.body.clientWidth - idPopup.document.all.puRegion.offsetWidth) / 2
}

function _pageReady()
{
idEditbox.document.body.oncontextmenu = new Function("return false")
if (g_state.szSearch!="")
idPopup.document.domain = idEditbox.document.domain = document.domain = g_state.szSearch
//_Editor_MoveSelection(false)
if (self.parent.RTELoaded)
self.parent.RTELoaded(self)

_setSize()
idEditor.style.visibility=""
}

function _drawToolbar()
{
var aSizes = new Array(23,23,23,4,47,23,23,23,6,23,23,23,6,24,23,23,23,6,23,23,32);
var aIds = new Array("cut","copy","paste","bar1","fontstyle","bold","italic","underline","bar3","left","center","right","bar4","orderedlist","unorderedlist","outdent","indent","bar5","link","textcolor","emoticon")
var aTips = new Array(L_TIPCUT_TEXT,L_TIPCOPY_TEXT,L_TIPPASTE_TEXT,"",L_TIPFSTYLE_TEXT,L_TIPB_TEXT,L_TIPI_TEXT,L_TIPU_TEXT,"",L_TIPLJ_TEXT,L_TIPCJ_TEXT,L_TIPRJ_TEXT,"",L_TIPOL_TEXT,L_TIPUL_TEXT,L_TIPDINDENT_TEXT,L_TIPIINDENT_TEXT,"",L_TIPLINK_TEXT,L_TIPFGCOLOR_TEXT,L_TIPEMOTICON_TEXT)
var aCommand = new Array("_Format('cut')","_Format('copy')","_Format('paste')",null,"_CPopup_Show('font')","_Format('bold')","_Format('italic')","_Format('underline')",null,"_Format('Justify','Left')","_Format('Justify','Center')","_Format('Justify','Right')",null,"_Format('insertorderedlist')","_Format('insertunorderedlist')","_Format('outdent')","_Format('indent')",null,"_CPopup_Show('Link')","_CPopup_Show('ForeColor')","_CPopup_Show('Emoticon')")
var sz = "<DIV ID=idStandardBar><NOBR>", iLeft=0, iHeight=24
for (var i = 0 ; i < aSizes.length; i++)
{
sz        += ""
+ "<SPAN CLASS=tbButton ONKEYPRESS=\"if (event.keyCode==13) {" + aCommand[i] + ";event.keyCode=0}\" " + (aTips[i]=="" ? "" : ("TABINDEX=" + (i+1))) + " "
+        "ID=\"tb" + aIds[i] + "\" "
+        "STYLE=\"width: " + aSizes[i] + ";height:" + iHeight
+        "\""
+ ">"
+        "<SPAN "
+        "STYLE=\""
+        "position:absolute;"
+        "width:" + aSizes[i] + ";height:" + iHeight + ";"
+        "clip: rect(0 " + aSizes[i] + " " + iHeight + " 0)"
+        "\""
+        ">"
+        "<IMG "
+        "TITLE=\"" + aTips[i] + "\" "
+        "ONCLICK=\"" + aCommand[i] + "; event.cancelBubble=true\" "
+        "ONMOUSEDOWN=\"if (event.button==1) this.style.pixelTop=-" + (iHeight*2) + "\" "
+        "ONMOUSEOVER=\"this.style.pixelTop=-" + iHeight + "\" "
+        "ONMOUSEOUT=\"this.style.pixelTop=0\" "
+        "ONMOUSEUP=\"this.style.pixelTop=-" + iHeight + "\" "
+        "SRC=\"" + L_TOOLBARGIF_TEXT + "\" "
+        "STYLE=\"position:absolute;top:0;left:-" + iLeft + "\""
+        ">"
+        "</SPAN>"
+ "</SPAN>"
+ (aTips[i]=="" ? "</NOBR><NOBR>" : "")
iLeft += aSizes[i]
}
document.write(sz + "</DIV>")
}

// _CState
function _CState()
{
this.selection        = null
this.bMode        = true
this.customButtons = false
this.css = this.bgColor        = ""
this.defaultSkin        = document.styleSheets.skin.cssText
this.popupSkin        = document.styleSheets.popupSkin.cssText
this.aLinks        = new Array()
this.szSearch        = location.search.substring(1)
this.aBindings        = new Array()
this.aListPopups        = new Object()
this.aCache        = new Object()
this.RestoreSelection        = _CState_RestoreSelection
this.GetSelection        = _CState_GetSelection
this.SaveSelection        = _CState_SaveSelection
}

function _CState_RestoreSelection()
{
if (this.selection) this.selection.select()
}

function _CState_GetSelection()
{
var oSel = this.selection
if (!oSel) {
oSel = idEditbox.document.selection.createRange()
oSel.type = idEditbox.document.selection.type
}
return oSel
}

function _CState_SaveSelection()
{
g_state.selection = idEditbox.document.selection.createRange()
g_state.selection.type = idEditbox.document.selection.type
}

// POPUP (Link, table and image popup need to be worked on)
function _CPopup_Init()
{
var sz = ""
+ "<HTML ID=popup>"
+        "<STYLE>"
+        document.styleSheets.popupSkin.cssText
+        "</STYLE>"
+        "<BODY "
+        "ONSCROLL=\"return false\" SCROLL=no TABINDEX=-1 "
+        "ONSELECTSTART=\"return event.srcElement.tagName=='INPUT'\" "
+        "><DIV ID=puRegion>"
+        "<TABLE ID=header>"
+        "<TR>"
+        "<TD NOWRAP ID=caption></TD>"
+        "<TD VALIGN=middle ALIGN=RIGHT><DIV ID=close ONCLICK=\"parent._CPopup_Hide()\">x</DIV></TD>"
+        "</TR>"
+        "</TABLE>"
+        "<DIV ALIGN=CENTER ID=content></DIV>"
+        "</DIV></BODY>"
+ "</HTML>"
idPopup.document.open("text/html","replace")
idPopup.document.write(sz)
idPopup.document.close()
}

function _CPopup_Hide()
{
document.all.idPopup.style.zIndex=-1
document.all.idPopup.style.visibility = "hidden"
idPopup.document._type = ""
idPopup.document._show = false
idPopup.document.onkeydown=idPopup.document.onmouseover=idPopup.document.onclick = null
// commented out by Bob..
//idEditbox.focus()
}

function _CPopup_Show(szType)
{
var oRenderer, szCacheKey = "PopupRenderer." + szType
if (idPopup.document._type == szType)
_CPopup_Hide()
else
{
document.all.idPopup.style.zIndex = -1
oRenderer = g_state.aCache[szCacheKey]
if ((!oRenderer) || ("Link"==szType))
g_state.aCache[szCacheKey] = oRenderer = new _CPopupRenderer(szType)
// Force Sizing
document.all.idPopup.style.visibility = ""
idPopup.document.all.puRegion.style.pixelHeight = idPopup.document.all.puRegion.style.pixelWidth = 100
idPopup.document._type        = szType
idPopup.document._renderer        = oRenderer
idPopup.document.all.caption.innerText        = oRenderer.GetCaption()
idPopup.document.all.content.innerHTML        = oRenderer.GetHTML()
idPopup.document.onkeydown        = new Function("this._renderer.OnKeyDown()")
idPopup.document.onmouseover        = new Function("this._renderer.OnMouseOver()")
idPopup.document.onclick        = new Function("this._renderer.OnClick()")
oRenderer.ResetContext(idPopup.document)
setTimeout("_CPopupRenderer_Display('" + szType + "')",0)

}
}

function _CPopupRenderer_Display(szType) {
var oRenderer, szCacheKey = "PopupRenderer." + szType
oRenderer = g_state.aCache[szCacheKey]
if (oRenderer.autoSize) {
idPopup.document.all.puRegion.style.pixelHeight = document.all.idPopup.style.pixelHeight = idPopup.document.all.puRegion.offsetHeight
idPopup.document.all.puRegion.style.pixelWidth = document.all.idPopup.style.pixelWidth = idPopup.document.all.puRegion.offsetWidth + 50
document.all.idPopup.style.pixelLeft = (document.body.clientWidth - idPopup.document.all.puRegion.offsetWidth) / 2
}
else {
idPopup.document.all.puRegion.style.pixelHeight = document.all.idPopup.style.pixelHeight = document.body.clientHeight - idToolbar.offsetHeight-20 
idPopup.document.all.puRegion.style.pixelWidth = document.all.idPopup.style.pixelWidth = document.body.clientWidth - 50
document.all.idPopup.style.pixelLeft = 25
}
document.all.idPopup.style.zIndex=2
idPopup.document._show = true
idPopup.focus()
}

function _CPopupRenderer(szType)
{
        this.szType        = szType
        this.elCurrent        = this.oDocument = null
        this.ResetContext = _CPopupRenderer_ResetContext
        this.GetCaption        = _CPopupRenderer_GetCaption
        this.GetHTML        = _CPopupRenderer_GetHTML
        this.autoSize        = true
        this.OnMouseOver = new Function()
        this.OnKeyDown        = _CListPopupRenderer_GenericOnKeyDown
        switch(szType)
        {
                case "font":
                        this.OnMouseOver= _CListPopupRenderer_OnMouseOver
                        this.OnKeyDown = _CListPopupRenderer_OnKeyDown
                case "ForeColor":
                        this.OnClick        = _CListPopupRenderer_OnClick
                        this.Highlight = _CListPopupRenderer_Highlight
                        this.Select        = _CListPopupRenderer_Select
                break
                default:
                        this.OnClick        = new Function()
                break
        }
        switch(szType)
        {
                case "font":
                        this.szCaption        = L_PUTITLEFONTFACE_TEXT
                        this.PrepareHTML        = _CFontFacesPopupRenderer_PrepareHTML
                        this.szHTML        = this.PrepareHTML()
                break
                case "Link":
                        this.szCaption        = L_PUTITLELINK_TEXT
                        this.PrepareHTML        = _CLinkPopupRenderer_PrepareHTML
                        this.szHTML        = this.PrepareHTML()
                break
                case "ForeColor":
                        this.szCaption        = L_PUTITLETEXTCOLOR_TEXT
                        this.szHTML        = "<DIV ID=ColorPopup ALIGN=CENTER>" + _CUtil_BuildColorTable("") + "</DIV>"
                break
                case "Emoticon":
                        this.szCaption        = L_PUTITLEEMOTICON_TEXT
                        this.PrepareHTML        = _CEmoticonRenderer_PrepareHTML
                        this.szHTML        = this.PrepareHTML()
                break
                default:
                        this.szCaption        = ""
                break
        }
}

function _CPopupRenderer_ResetContext(oDoc)
{
this.oDocument = oDoc
this.elCurrent = null
if (this.szType=="Table") {
var oSel        = idEditbox.document.selection.createRange()
var oBlock = (oSel.parentElement != null ? _CUtil_GetElement(oSel.parentElement(),"TABLE") : _CUtil_GetElement(oSel.item(0),"TABLE"))
if (oBlock!=null) {
oDoc.all.tabEdit.className=""
oDoc.all.tabEditBodytxtPadding.value = oBlock.cellPadding
oDoc.all.tabEditBodytxtSpacing.value = oBlock.cellSpacing
oDoc.all.tabEditBodytxtBorder.value = oBlock.border
oDoc.all.tabEditBodytxtBorderColor.value = oBlock.borderColor
oDoc.all.tabEditBodytxtBackgroundImage.value = oBlock.background
oDoc.all.tabEditBodytxtBackgroundColor.value = oBlock.bgColor
}
oDoc.elCurrent = oBlock
}
}

function _CPopupRenderer_GetCaption()
{
return this.szCaption
}

function _CPopupRenderer_GetHTML()
{
return this.szHTML
}

function _CEmoticonRenderer_PrepareHTML() {
var sz = "<DIV ALIGN=center style='width:225px'>"
for (var i=0; i < arEmoticons.length; i++)
{
sz += "<IMG TABINDEX=" + i + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT + arEmoticons[i] + "\" WIDTH=23 HEIGHT=23 HSPACE=1>"
if ((i+1)%9==0) sz+="<BR>"
}
sz+="</DIV>"
return sz
}

function _CEmoticonRenderer_Select(elImg) {
insertHTML("<IMG SRC=\"" + elImg.src + "\" WIDTH=" + elImg.width + " HEIGHT=" + elImg.height + ">")
g_state.RestoreSelection()
_CPopup_Hide()
}

function _CFontFacesPopupRenderer_PrepareHTML()
{
var sz = "<TABLE ALIGN=center ID=idList CELLSPACING=1 CELLPADDING=0 STYLE=\"font-size:16px\">"
for (var i=0; i < defaultFonts.length; i++)
{
sz += ""
+ "<TR>"
+        "<TD NOWRAP " + "_item=" + i + " " + "ALIGN=center >"
+        "<FONT FACE=\"" + defaultFonts[i][0] + "\">" + defaultFonts[i][1] + "</FONT>" + (defaultFonts[i][2] ? ("(" + defaultFonts[i][1] + ")") : "")
+        "</TD>"
i++
if (i < defaultFonts.length )
sz += ""
+        "<TD NOWRAP " + "_item=" + i + " " + "ALIGN=center >"
+        "<FONT FACE=\"" + defaultFonts[i][0] + "\">" + defaultFonts[i][1] + "</FONT>" + (defaultFonts[i][2] ? ("(" + defaultFonts[i][1] + ")") : "")
+        "</TD>"
else sz += "<TD></TD>"
sz += "</TR>"
}
sz += "</TABLE>"
return sz
}

function _CListPopupRenderer_OnClick()
{
var elTD = _CUtil_GetElement(this.oDocument.parentWindow.event.srcElement, "TD")
if (elTD && elTD._item) this.Select(elTD)
}

function _CListPopupRenderer_GenericOnKeyDown() {
var ev        = this.oDocument.parentWindow.event
if (ev.keyCode==27) _CPopup_Hide()
}

function _CListPopupRenderer_OnKeyDown()
{
var el
var iRow = iCell        = 0
var ev        = this.oDocument.parentWindow.event
var idList = this.oDocument.all.idList
var elTR        = _CUtil_GetElement(this.elCurrent,"TR")
var elTD        = _CUtil_GetElement(this.elCurrent,"TD")
if (elTR != null)
{
iRow        = elTR.rowIndex
iCell = elTD.cellIndex
}
switch (ev.keyCode)
{
case 37:
iCell--
if (iCell < 0)
iCell = idList.rows[iRow].cells.length-1
break
case 38:
iRow--
if (iRow < 0)
iRow = idList.rows.length-1
break
case 39:
iCell++
if (iCell > idList.rows[iRow].cells.length-1)
iCell = 0
break
case 40:
iRow++
if (iRow > idList.rows.length-1)
iRow = 0
break
case 13:
break;
case 27:
_CPopup_Hide()
break;
default:
return;
}
el = idList.rows[iRow].cells[iCell]
if (el && el._item)
if (13 == ev.keyCode) {
ev.keyCode=0
this.Select(el)
}
else
this.Highlight(el)
}

function _CListPopupRenderer_OnMouseOver()
{
var el = _CUtil_GetElement(this.oDocument.parentWindow.event.srcElement, "TD")
if (el && el._item && el != this.elCurrent)
this.Highlight(el)
}

function _CListPopupRenderer_Highlight(el)
{
var elC = this.elCurrent
if (elC) elC.style.borderWidth = elC.style.borderColor = elC.style.borderStyle = ""
el.style.borderWidth        = "1px"
el.style.borderColor        = "green"
el.style.borderStyle        = "solid"
this.elCurrent        = el
}

function _CListPopupRenderer_Select(elTD)
{
g_state.RestoreSelection()
var el = elTD.children[0]
switch (this.szType)
{
case "font":
_Format("FontName",el.face)
break
case "ForeColor":
_Format("ForeColor", elTD.bgColor)
break
}
_CPopup_Hide()
}

function _CLinkPopupRenderer_AddLink(d)
{
var szURL = d.all.urlValue.value
var szType = d.all.urlType[d.all.urlType.selectedIndex].text
var oSel = g_state.GetSelection()
var sType = oSel.type
szURL = ((0 == szURL.indexOf("mailto:") || 0 == szURL.indexOf("http://") || 0 == szURL.indexOf("ftp://")) ? "" : szType) + szURL
if (szURL!="")
{
if ((oSel.parentElement) && (oSel.text==""))
{
oSel.expand("word")
if (oSel.text=="")
{
var oStore = oSel.duplicate()
if (d.all.pageList) {
var idx = d.all.pageList.selectedIndex
if (d.all.pageList[idx].value==szURL)
oSel.text = d.all.pageList[idx].text
else
oSel.text = szURL
}
else
oSel.text = szURL
oSel.setEndPoint("StartToStart",oStore)
}
oSel.select()
sType="Text"
}
if ((oSel.item) && (oSel.item(0).tagName=="IMG"))
{
oSel.item(0).width = oSel.item(0).offsetWidth
oSel.item(0).height = oSel.item(0).offsetHeight
oSel.item(0).border = (d.all.displayBorder.checked) ? 1 : ""
}
if (d.all.urlValue.value!="")
oSel.execCommand("CreateLink",false,szURL)
else
oSel.execCommand("UnLink",false,szURL)
}
idEditbox.focus()
}

function _CLinkPopupRenderer__UpdateURL(oDoc,szURL) {
var szType = szURL.substring(0,szURL.indexOf(":"))
for (var i=0;i<oDoc.all.urlType.length;i++)
if (oDoc.all.urlType[i].value==szType)
oDoc.all.urlType.selectedIndex = i
if (("http"==szType) || ("ftp"==szType))
szURL = szURL.substring(szURL.indexOf("//")+2)
else
szURL = szURL.substring(szURL.indexOf(":")+1)
oDoc.all.urlValue.value = szURL
}

function _CLinkPopupRenderer_PrepareHTML()
{
var d = this.oDocument
var oSel = g_state.GetSelection()
var oEl, sType = oSel.type, bImg = false, szURL = sz = ""
if (oSel.parentElement)
{
oEl = _CUtil_GetElement(oSel.parentElement(),"A")
}
else
{
oEl = _CUtil_GetElement(oSel.item(0),"A")
bImg = oSel.item(0).tagName=="IMG"
}
if (oEl)
szURL = oEl.href
sz ="<TABLE ALIGN=center>"
if (g_state.aLinks.length>0)
{
sz += ""
+ "<TR>"
+        "<TD>"
+        L_LINKSELECT_TEXT
+        "<SELECT ID=pageList ONCHANGE=\"parent._CLinkPopupRenderer__UpdateURL(this.document,this[this.selectedIndex].value)\">"
+        "<OPTION VALUE=''>"
+        "=="
+        L_LINKSELECTPAGE_TEXT
+        "=="
+        "</OPTION>"
for (var i = 0; i < g_state.aLinks.length; i++)
{
sz += ""
+ "<OPTION VALUE=\"" + g_state.aLinks[i][0] + "\" "
+        (oEl && (g_state.aLinks[i][0]==oEl.href) ? "SELECTED" : "")
+ ">"
+        g_state.aLinks[i][1]
+ "</OPTION>"
}
sz += "</SELECT>"
}
var arTypes = new Array("http","ftp","mailto")
var arText = new Array("http://","ftp://","mailto:")
var szType = szURL.substring(0,szURL.indexOf(":"))
if (("http"==szType) || ("ftp"==szType))
szURL = szURL.substring(szURL.indexOf("//")+2)
else
szURL = szURL.substring(szURL.indexOf(":")+1)
sz += ""
+ "<BR>"
+ L_LINKWEB_TEXT
+ "<NOBR><SELECT ID=urlType>"
for (var i=0;i<arTypes.length;i++) {
sz+= "<OPTION VALUE='" + arTypes[i] + "' "
+        (arTypes[i]==szType ? " SELECTED " : "")
+ ">" + arText[i]
}
sz += "</SELECT><INPUT ID=urlValue SIZE=45 VALUE=\"" + szURL + "\" TYPE=text></NOBR>"
if (bImg)
{
sz += ""
+ "<BR>"
+ "<INPUT TYPE=checkbox ID=displayBorder " + ((oSel.item(0).border!=0) ? " checked " : "") + ">"
+ L_LINKIMGBORDER_TEXT
}
sz += ""
+        "</TD>"
+        "</TR>"
+        "<TR>"
+        "<TD ALIGN=center>"
+        "<INPUT ONCLICK=\"parent._CLinkPopupRenderer_AddLink(this.document);parent._CPopup_Hide()\" TYPE=submit ID=idSave VALUE=\"" + L_INSERT_TEXT + "\"> <INPUT ONCLICK=\"parent._CPopup_Hide()\" TYPE=reset ID=idCancel VALUE=\"" + L_CANCEL_TEXT + "\">"
+        "</TD>"
+        "</TR>"
+ "</TABLE>"
return sz
}


// UTIL
function _CUtil_GetElement(oEl,sTag)
{
while (oEl!=null && oEl.tagName!=sTag)
oEl = oEl.parentElement
return oEl
}
function _CUtil_BuildColorTable(sID,fmt,szClick)
{
var sz, cPick = new Array("00","33","66","99","CC","FF"), iCnt=2
var iColors = cPick.length, szColor = ""
sz = "<TABLE CELLSPACING=0 CELLPADDING=0><TR><TD VALIGN=middle><DIV CLASS=currentColor ID=\"" + sID + "Current\">&nbsp;</DIV></TD><TD>"
+ "<TABLE ONMOUSEOUT=\"document.all." + sID + "Current.style.backgroundColor = ''\" ONMOUSEOVER=\"document.all." + sID + "Current.style.backgroundColor = event.srcElement.bgColor\" CLASS=colorTable CELLSPACING=0 CELLPADDING=0 ID=\"" + sID + "\">"
for (var r=0;r<iColors;r++) {
sz+="<TR>"
for (var g=iColors-1;g>=0;g--)
for (var b=iColors-1;b>=0;b--) {
szColor = cPick[r]+cPick[g]+cPick[b]
sz+="<TD"
+ " BGCOLOR=\"#" + szColor + "\""
+ "_item=\"" + szColor + "\" "
+ "TITLE=\"#" + szColor + "\" "
+ (szClick ? "ONCLICK=\"" + szClick + "\" " : "")
+ ">&nbsp;</TD>"
}
sz+="</TR>"
}
sz+="</TABLE></TD></TR></TABLE>"
return sz
}

function _CUtil_GetBlock(oEl)
{
var sBlocks = "|H1|H2|H3|H4|H5|H6|P|PRE|LI|TD|DIV|BLOCKQUOTE|DT|DD|TABLE|HR|IMG|"
while ((oEl!=null) && (sBlocks.indexOf("|"+oEl.tagName+"|")==-1))
oEl = oEl.parentElement
return oEl
}